var timeLine={
	baseOption:'', // 默认全局对象
	goCAllback:'',
	indexIng:'',
	t:'',
	firstG:true,
	lengths:'',
	flag:true,
	limit:false,
	thisTime:false,
	radar:false,
	step:2000,
	moveF:false,
	// 生成时间轴
	initT:function(newOption){
		timeLine.baseOption = newOption;
		$(".btns_ul").html('');
		newOption.callBack(newOption.titles);
		//console.log(newOption)
		$(".btns_ul").css({width:timeLine.baseOption.length*($(".btns_ul_data").parent().width()+6)});
	},

	//----------初始化数据
	cleanT:function(callback,cleanData){
			timeLine.thisTime=cleanData.thisTime;
			timeLine.limit=cleanData.limit;
			var Thisdate=new Date();
			var thisHours=Thisdate.getHours();
			var zhenhour=Thisdate.getHours();
			var thisDate=Thisdate.getDate();
			var thisYears=Thisdate.getFullYear();
			var thisMouth=Thisdate.getMonth();
			//长度
			var dateTime=$("#datePicker").val();
		 	if(Number(dateTime.slice(0,4))==thisYears&&Number(dateTime.slice(5,7))==thisMouth+1&&Number(dateTime.slice(8,10))==thisDate){
			 	timeLine.lengths=cleanData.limit?parseInt(thisHours)+1:timeLine.baseOption.length;
			 	//console.log("今天")
			 }else{
			 	timeLine.lengths=timeLine.baseOption.length;
			 	//console.log("不是今天")
			};
		 	//indexing的值
			timeLine.indexIng=cleanData.thisTime?parseInt(thisHours)-1:-1;
			if(cleanData.thisTime=="last"){
				timeLine.indexIng=timeLine.baseOption.length-2;
			};
//			if(cleanData.limit){
				timeLine.addFeiqi();
//			};
			timeLine.goCAllback=callback;
			timeLine.eachBtn();
			$(".btns_ul_data").attr("mapData",'');
			clearInterval(timeLine.t);
			timeLine.radar=false;
			timeLine.flag=true;
			$("#pasue_time").html(" <i class='fa fa-play fa-2x'></i>").attr("title","开始");
			timeLine.moveF=true;
			timeLine.move();
			if(timeLine.firstG){
				timeLine.firstG=false;
				timeLine.goTimeline();
				timeLine.timeScroll();
			};
	},
	//时间轴加限制
	addFeiqi:function(){
		$(".btns_ul_data").removeClass("feiqi");
		$(".btns_ul_data").each(function(index){
			if(index>=timeLine.lengths){
				$(this).addClass("feiqi");
			}
		})
	},
	//执行轮播
	move:function(){
		$(".xdsoft_time_box").removeClass("xdsoft_time_box_wjp");
		//console.log(timeLine.baseOption)
		timeLine.indexIng++;
		if(timeLine.indexIng>=timeLine.lengths){
			timeLine.indexIng=0;
		};
		$(".btns_ul_data").removeClass("activeBtn");
		$(".btns_ul_data").eq(timeLine.indexIng).addClass("activeBtn");
		var data={
			time:$("#datePicker").val(),
			hour:$(".btns_ul_data").eq(timeLine.indexIng).siblings("div").text(),
			index:timeLine.indexIng
		};
		timeLine.goCAllback(data,timeLine.baseOption,$(".btns_ul_data").eq(timeLine.indexIng).attr('attr_year'),timeLine.radar,$(".btns_ul_data").eq(timeLine.indexIng));
		if(timeLine.moveF){
			timeLine.posiTion();
		};
	},

	//鼠标移入时间轴事件
	eachBtn:function(){
		$(".btns_ul_data").each(function(index){
			$(this).unbind();
			var that=index;
			$(this).mouseover(function(){
				timeLine.moveF=false;
				if(that<timeLine.lengths){
					clearInterval(timeLine.t);
					$(".btns_ul_data").removeClass("activeBtn");
					$(this).addClass("activeBtn");
					timeLine.indexIng=that-1;
					timeLine.move();
				}
			});
			$(this).mouseout(function(){
				timeLine.moveF=true;
				if(that<timeLine.lengths){
					if(timeLine.flag){

					}else{
						$("#pasue_time").html(" <i class='fa fa-pause fa-2x'></i>").attr("title","暂停");
						timeLine.t=setInterval(timeLine.move,timeLine.step);
					};
				};
			})
		});
	},
	//时间轴上的操作；
	goTimeline:function(){

		//暂停
		$("#pasue_time").click(function(){
			if(timeLine.flag){
				timeLine.flag=false;
				$(this).html(" <i class='fa fa-pause fa-2x'></i>").attr("title","暂停");
				timeLine.radar=true;
				timeLine.t=setInterval(timeLine.move,timeLine.step);
			}else{
				timeLine.radar=false;
				timeLine.flag=true;
				$(this).html(" <i class='fa fa-play fa-2x'></i>").attr("title","开始");
				clearInterval(timeLine.t);
			}

		});
		//前一个
		$("#over_time").click(function(){
				timeLine.indexIng--;
				timeLine.indexIng--;
				if(timeLine.indexIng<0){
					timeLine.indexIng=-1;
				};
				$(".btns_ul_data").removeClass("activeBtn");
				$(".btns_ul_data").eq(timeLine.indexIng).addClass("activeBtn");
				timeLine.move();

		});
		//下一个
		$("#next_time").click(function(){
				timeLine.move();
		});
	},

	//当前点定位
	posiTion:function(){
		var pWidth=$("#btns_ul_parent").width();
//		var left=parseInt($(".btns_ul").css("margin-left"));
		var length=$(".btns_ul").find("li").length;
		var activeLi=$(".activeBtn").parent();
		var index=$(".btns_ul li").index(activeLi);
		var alllength=index*($(".btns_ul_data").parent().width()+6);
		var endLength=alllength-pWidth;
		if(alllength-pWidth>-10){
			$(".btns_ul").css({"margin-left":-endLength});
		}else if(alllength<=pWidth){
			$(".btns_ul").css({"margin-left":0});
		}
	},

	timeScroll:function(){
		//点击模拟时间轴滚动条
		var amounts=1;
		$("#scroll_left").click(function(){
			//console.log(amounts)
			var pWidth=$("#btns_ul_parent").width();
			var aWidth=$(".btns_ul").width();
			var left=-parseInt($(".btns_ul").css("margin-left"));
			//console.log(left)
			if(left>0){
				var newLeft=left-pWidth>0?left-pWidth/1.5:0;
				$(".btns_ul").css({"margin-left":-newLeft});
			}

		});

		$("#scroll_right").click(function(){
			//console.log(amounts)
			var pWidth=$("#btns_ul_parent").width();
			var aWidth=$(".btns_ul").width();
			var left=-parseInt($(".btns_ul").css("margin-left"));
			//console.log(left)
			if(left+pWidth<aWidth){
				var newLeft=left+pWidth*2>aWidth?aWidth-pWidth:left+pWidth/1.5;
				$(".btns_ul").css({"margin-left":-newLeft});
			};
		});
	}

}

